package org.csu.jpetstore_cms.controller;

import lombok.extern.slf4j.Slf4j;
import org.csu.jpetstore_cms.pojo.Order;
import org.csu.jpetstore_cms.pojo.Result;
import org.csu.jpetstore_cms.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PutMapping("/insert/{orderId}")
    public Result insertOrder(@RequestBody Order order){
        orderService.insertOrder(order);
        System.out.println(order);
        return Result.success();
    }
    @DeleteMapping("/deleteAll")
    public Result deleteAllOrder(){
        orderService.deleteAllOrder();
        System.out.println("----");
        return Result.success();
    }
    @DeleteMapping("/delete/{orderId}")
    public Result deleteOrder(@PathVariable String orderId){
        orderService.deleteOrder(orderId);
        System.out.println("----");
        return Result.success();
    }
    @PostMapping("/update/{orderId}")
    public Result updateOrder(@PathVariable String orderId,@RequestBody Order order){
        orderService.updateOrder(orderId,order);
        System.out.println("----");
        return Result.success();
    }
    @GetMapping("/getAll")
    public Result getAllOrder(){
        List<Order> orderList = orderService.getAllOrder();
        System.out.println(orderList);
        return Result.success(orderList);
    }
    @GetMapping("/get/{orderId}")
    public Result getOrder(@PathVariable String orderId){
        Order order = orderService.getOrder(orderId);
        System.out.println(order);
        return Result.success(order);
    }
    @GetMapping("/getAllUnshipped")
    public Result getAllUnshippedOrder(){
        List<Order> orderList = orderService.getAllUnshippedOrder();
        System.out.println(orderList);
        return Result.success(orderList);
    }
    @GetMapping("/isOrderShipped/{orderId}")
    public Result isOrderShipped(@PathVariable String orderId){
        boolean isShipped = orderService.isOrderShipped(orderId);
        System.out.println(isShipped);
        return Result.success(isShipped);
    }

    @PostMapping("/ship/{orderId}")
    public Result shipOrder(@PathVariable String orderId){
        boolean isShipped = orderService.shipOrder(orderId);
        System.out.println(isShipped);
        return Result.success(isShipped);
    }

}
